import axios from 'axios'

// import { Message } from 'element-ui'

import store from '@/store'

const request = axios.create({
  baseURL: 'http://likede2-admin.itheima.net/likede/',
  timeout: 20000 // request timeout
})

// 请求拦截器
request.interceptors.request.use(
  config => {
    const token = store.state.user.token
    if (token) config.headers.Authorization = token
    return config
  },
  error => {
    return Promise.reject(error)
  }
)

// 响应拦截器
request.interceptors.response.use(
  response => {
    // const { success, msg } = response.data
    // if (success) {
    //   // console.log(response.data)
    // }
    return response.data
  },
  error => {
    return Promise.reject(error)
  }
)

export default request
